﻿@implements IAsyncDisposable
@inject IJSRuntime JS
<button @onclick="qqsq">设置允许访问哪些串口</button>

@code {
    IJSObjectReference module;

    /// <summary>
    /// 请求授权
    /// </summary>
    /// <returns></returns>
    async Task qqsq()
    {
       // var r = await JS.InvokeAsync("requestPort");
      var r =  await module.InvokeAsync<object>("requestPort");

       // await module.InvokeVoidAsync("requestPort");
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/BXJG.BlazorSerial/RequestPort.razor.js");
        }
    }

    public async ValueTask DisposeAsync()
    {
        if (module is not null)
        {
            // await module.InvokeVoidAsync("dispose", container); //这里组件已经不在了，dom没有了，调用会报错
            await module.DisposeAsync();
        }
    }
}
